package priv.yiyuan.example.design.chain;

/**
 * @author YiYuan
 * @data 2025/10/14
 * @apoNote
 */
public abstract class DataProcessor {

    protected DataProcessor nextProcessor;

    protected AbstractDataHandler internalHandler;

    public DataProcessor(AbstractDataHandler internalHandler) {
        this.internalHandler = internalHandler;
    }

    public void setNextProcessor(DataProcessor nextProcessor) {
        this.nextProcessor = nextProcessor;
    }

    public void process(RawData data) {
        if (!data.isValid()) {
            System.out.println("数据在上一个环节已标记为无效, 跳过当前处理器: " + this.getClass().getSimpleName());
            return;
        }

        internalHandler.handle(data);

        if (data.isValid() && nextProcessor != null) {
            nextProcessor.process(data);
        }
        else if (!data.isValid()) {
            System.out.println("数据在 " + this.getClass().getSimpleName() + "处理后变为无效, 责任链中断。");
        }
    }
}
